#!/bin/bash

echo "🚀 开始构建 Windows 版本..."

# 检查 cargo-zigbuild 是否安装
if ! command -v cargo-zigbuild &> /dev/null; then
    echo "❌ 未找到 cargo-zigbuild"
    echo "正在安装 cargo-zigbuild..."
    cargo install cargo-zigbuild
fi

# 检查 zig 是否安装
if ! command -v zig &> /dev/null; then
    echo "❌ 未找到 zig"
    echo "请运行: brew install zig"
    exit 1
fi

# 添加目标平台
echo "📦 添加目标平台..."
rustup target add x86_64-pc-windows-gnu

# 编译
echo "🔨 正在编译..."
cargo zigbuild --release --target x86_64-pc-windows-gnu

if [ $? -eq 0 ]; then
    # 创建发布目录
    echo "📁 创建发布包..."
    mkdir -p dist
    cp target/x86_64-pc-windows-gnu/release/timed_request.exe dist/
    cp config.toml dist/

    echo ""
    echo "✅ 编译成功！"
    echo "📂 输出目录: dist/"
    ls -lh dist/
else
    echo "❌ 编译失败"
    exit 1
fi